package demo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2023-08-12
 * Time: 21:24
 */
public class Test {
    public static int reverse (int x) {
        // write code here
        long sum = 0;
        while (x != 0){
            sum = sum * 10 + x % 10;
            if(sum > Integer.MAX_VALUE || sum < Integer.MIN_VALUE){
                return 0;
            }
            x /= 10;
        }
        return (int)sum;
    }
    public static void main(String[] args) {
        int num = 12;
        int ret = reverse(num);
        System.out.println(ret);
    }
    public int FirstNotRepeatingChar (String str) {
        // write code here
        char[] charArray = new char[str.length()];
        charArray = str.toCharArray();
        int len = charArray.length;
        for (int i = 0; i < len; i++) {
            int count = 0;
            for (int j = 0; j < len; j++) {
                if (i == j) {
                    continue;
                }
                if (charArray[i] == charArray[j]) {
                    break;
                }
                count++;
                if (count == charArray.length - 1) {
                    return i;
                }
            }

        }
        return -1;

    }
    public static int FirstNotRepeatingChar1 (String str) {
        // write code here
        int len = str.length();
        int count = 0;
        char[] arry = new char[len];
        for (int i = 0; i < len; i++) {
            arry[i] = str.charAt(i);
        }
        for (int i = 0; i < len; i++) {
            for (int j = 0; j < len; j++) {
                if(i == j){
                    continue;
                }
                if(arry[i] == arry[j]){
                    break;
                }
                count++;
                if(count == len - 1){
                    return i;
                }
            }
        }
        return -1;

    }
    public static void main1(String[] args) {
        String str = "google";
        int ret = FirstNotRepeatingChar1(str);
        System.out.println(ret);
    }
}
